
{include file="public/head"}
<div class="main">
    {include file="public/left"}
    <div class="middle">
    {include file="public/header"}
    <div class='userinfo'>
        {include file="public/userleft"}
        <div class="online">
            <h3>{:__('提现申请')}</h3>
            <div>{:__('金币')}:{:__('现金')}=<span id="money_to_cash"></span>:1</div>
            <ul>
                <dl><span>{:__('您的余额(可提现金币)')}: $<span class="show_money" id="show_money"></span> </span></dl>
                <dl><span>{:__('请输入提现金额(现金)')}：</span><input id="money" class="layui-input" type="text"/><span>$（{:__('不支持小数')},{:__('最多提现9999$')}）</span></dl>
                <dl><h6>{:__('请选择支付方式')}：</h6></dl>
                <dl>
                    <p>
                        <input type="radio" checked/>
                        <i style="color: rgb(1,156,222);" class="fa fa-paypal" aria-hidden="true"></i>
                    </p>
                </dl>
                <dl><button id="pay" class="layui-btn layui-btn-primary">{:__('立刻提现')}</button></dl>
            </ul>
        </div>
    </div>
    {include file="public/foot"}
    </div>
    {include file="public/right"}
</div>
{include file="public/footer"}
<script>
    noLog();
    nowmoney = 0;
    function getMoney(){
        var userData = getLocalStorage('userData');
        var userdata = JSON.parse(userData);
        nowmoney = parseInt(userdata['money'])-parseInt(userdata['freeze']);
        $("#show_money").html(nowmoney);

        var mission_config = getLocalStorage('mission_config');
        var mission_configobj = JSON.parse(mission_config);
        $("#money_to_cash").html(mission_configobj['money_to_cash']);
    }
    $(document).on('keydown',"#money",function(e){
        var _this = $(this);
        var flag = keyLimit(e,4,_this);
        if(flag == false){
            return false;
        }
    });
    $(document).queue('user',function(){
        getMoney();
    });
    $("#pay").click(function(){
        var money = $("#money").val().replace(/ /g,'');
        var moneycopy = parseInt(money);
        if(money == '' || money == 0){
            layer.msg("{:__('提现金额不能为空')}",{icon:3});
            return false;
        }
        if(moneycopy>9999){
            layer.msg("{:__('提现金额不能大于')}9999$",{icon:3});
            return false;
        }
        if(moneycopy != money){
            layer.msg("{:__('提现金额不能为小数')}",{icon:3});
            return false;
        }
        var canmoney = parseInt(nowmoney/100);
        if(moneycopy>canmoney){
            layer.msg("{:__('提现金额不能大于')}"+canmoney+"$",{icon:3});
            return false;
        }
        $.ajax({
            url:'/api/cash/withdrawal',
            type:'post',
            data:{'cash':moneycopy,'token':token},
            success:function(ret){
                if(ret.code == 1){
                    layer.msg(ret.msg,{icon:1},function(){
                        objs = {'userData':1}
                        CacheLoad(objs);
                        $(document).queue('user',function(){
                            getMoney();
                            $("#money").val("");
                        });
                    });
                } else if(ret.code != 401){
                    layer.msg(ret.msg,{icon:2});
                }
            }
        })
    });
</script>